package org.dynamic.spring;

import org.dynamic.model.Person;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class PersonFactoryBean implements FactoryBean<Person>{
	
	@Value("${person.info}")
	private String personInfo; 
	
	@Override
	public Person getObject() throws Exception {
		Person person =  new  Person () ;      
        String []  infos =  personInfo.split ( "," ) ;  
        person.setId(infos[0]);
        person.setName(infos[1]); 
        person.setGender(infos[2]);
        person.setAddress(infos[3]);  
        return person;  
	}

	@Override
	public Class<?> getObjectType() {
		
		return Person.class;
	}

	@Override
	public boolean isSingleton() {
		
		return true;
	}

}
